"""
各种进行数据过滤的方法
"""
import numpy as np
from ..plot import plot_parm as pp
from ..sim_parm import *


def filter_average(x_axis, y_axis):
    temp = np.abs(y_axis)
    mean = temp.mean()
    temp2 = len(temp)
    k = 0
    for j in range(temp2):
        if np.abs(abs(y_axis[k]) - mean) > 0.1 * mean:
            y_axis = np.delete(y_axis, k)
            x_axis = np.delete(x_axis, k)
        else:
            k += 1
    return (x_axis, y_axis)


def filter_polyfit(x_axis, y_axis, order=3):
    """[summary]
        tttt
    Arguments:
        x_axis {[type]} -- [description]
        y_axis {[type]} -- [description]

    Keyword Arguments:
        order {int} -- [description] (default: {3})

    Returns:
        [type] -- [description]
    """
    f1 = np.polyfit(x_axis, y_axis, order)
    p1 = np.poly1d(f1)
    y_axis = p1(x_axis)
    return (x_axis, y_axis)


# fft 滤波
def filter_fft(x_axis, y_axis):
    fft_res = np.fft.fft(y_axis)  #注意fft从k=0开始，第一个值为纯实数，几何意义为平均值
    print(fft_res)
    min_dstc = x_axis[1] - x_axis[0]
    fft_fre = np.fft.fftfreq(len(x_axis), min_dstc)
    # 开始滤波，先求频率域上的平均值，再将频率域上远超平均值的部分舍去
    ifft_res = np.fft.ifft(fft_res)